Skip to content

Conversation

@Nithurshen
Copy link
Contributor


This PR adds a regression test for issue #62705.

The original issue reported a TypeError: Cannot interpret 'period[D]' as a data type when .pivot() was called on an empty DataFrame where the values column had a PeriodDtype.

As noted in the issue, this bug was already fixed on main, but it lacked a specific regression test to prevent this from reoccurring.

This new test:

  1. Creates an empty DataFrame: pd.DataFrame({"index": [], "columns": [], "values": []})
  2. Casts the values column to a PeriodDtype (parametrized for "D", "M", "Q", "Y").
  3. Calls .pivot() and asserts that the operation completes without an error.
  4. Validates that the resulting empty pivoted DataFrame has the correct empty float64 index/columns and the original PeriodDtype for its data, which matches the behavior of the fixed pivot operation.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Nov 6, 2025
@mroeschke mroeschke added this to the 3.0 milestone Nov 6, 2025
@mroeschke mroeschke merged commit 0627903 into pandas-dev:main Nov 6, 2025
46 checks passed
@mroeschke
Copy link
Member

Thanks @Nithurshen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing pandas testing functions or related to the test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Pivoting empty DataFrame fails with period-like dtypes

2 participants